import { post, request } from "@/utils/request";
import ApiResult from "./base/ApiResult";
import {
  IGoodsCateItem,
  IDeliverData,
  IDeliverItem,
  IGoodsPageData,
  IGoodsPageRow,
  IStoreGoodsPageRow,
  IStoreGoodsPageData,
  ISupplierItem,
  IMallPageItem,
  ICreateMallData,
  IOrderPageRow,
  IOrderPageData,
  IOrderStatisticsItem,
  IOrderDetailData,
  IOrderDetail,
  IAfterSaleOrderPageData,
  IAbnormalDetailData,
  IAbnormalOrderDetail,
  IStoreAddGoodsData,
  ISaveUpdateCategoryData,
  IUpdateProductData,
  IMallPageData,
  IStoreGoodsPageDataOption,
  ICurrencyItem,
  IOrderConfig,
  IStoreGoodsDetail,
  IStoreProductRow,
  IMerchantCategoryOption,
  IGoodsStatic,
  IDeliverConfig,
  IOrderConfigData,
  ISaveVipPriceData,
  IMallCouponDefineInfo
} from "./modules/pointsMall";

export const getCurrencyTypes: () => Promise<
  ApiResult<ICurrencyItem[]>
> = () => {
  return request("extensions/currency/manage/getCurrencys", {});
};

/**
 * 获取已存在的商城, 商城列表
 */
export const getMallList: () => Promise<ApiResult<IMallPageItem[]>> = () => {
  return request("mall/admin/application/getApps", {});
};

/**
 * 创建商城
 */
export const createMall: (data: ICreateMallData) => Promise<ApiResult<null>> = (
  data
) => {
  return request("mall/admin/application/addApp", data);
};

/**
 * 获取积分商城商品
 */
export const getMallGoodsPage: (
  data: IGoodsPageData
) => Promise<ApiResult<IGoodsPageRow[]>> = (data) => {
  return request("mall/admin/product/pageProduct", data);
};

export const getMallGoodsPage2: (
  data: IGoodsPageData
) => Promise<ApiResult<IGoodsPageRow[]>> = (data) => {
  return request("mall/admin/product/pageProduct2", data);
};

/**
 * 获取商家商品列表 - 商品选择器
 */
export const getStoreGoodsList: (
  data: IStoreGoodsPageData
) => Promise<ApiResult<IStoreGoodsPageRow[]>> = (data) => {
  return request("mall/admin/product/pageStoreProduct", data);
};

/**
 * 获取商家商品分类
 */
export const getMerchantCategory: (data: IStoreGoodsPageDataOption) => Promise<
  ApiResult<IMerchantCategoryOption[]>
> = (data) => {
  return request("mall/admin/product/getMerchantCategory", data);
};

/**
 * 商品选择器 - 选择商品 - 获取商家商品详情
 * @param data
 */
export const getStoreGoodsDetail: (data: {
  id: string;
  mallId?: number | string
}) => Promise<ApiResult<IStoreGoodsDetail>> = (data) => {
  return request("mall/admin/product/getStoreGoodsDetail", data);
};

/**
 * 保存单条商品 + 规格
 * @param data
 */
export const addGoods: (data: IStoreGoodsDetail) => Promise<ApiResult<any>> = (
  data
) => {
  return request("mall/admin/product/addGoods", data);
};

/**
 * 保存新增商品
 * @param data
 */
export const addProducts: (
  data: IStoreAddGoodsData
) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/addProducts", data);
};

/**
 * 获取商品详情 - 编辑商品
 * @param data
 */
export const getGoodsDetail: (data: {
  id: number | string;
}) => Promise<ApiResult<IGoodsPageRow>> = (data) => {
  return request("mall/admin/product/getDetail", data);
};

/**
 * 商品管理 - 编辑商品保存
 * @param data
 */
export const editGoods: (
  data: IUpdateProductData
) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/updateGoods", data);
};

/**
 * 获取商品数量统计
 * @param data
 */
export const getGoodsStatics: (data: {
  id: number;
}) => Promise<ApiResult<IGoodsStatic>> = (data) => {
  return request("mall/admin/product/goodsStatics", data);
};

/**
 * 商品列表 - 删除商品
 * @param data
 */
export const deleteGoods: (data: {
  id: number;
  name: any;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/delGoods", data);
};

/**
 * 商品列表切换上下线状态
 * @param data
 */
export const switchGoodsStatus: (data: {
  id: number;
  name: any;
  onlineStatus: number;
  spes?: {id: string, onlineStatus: number, stock: number, type: string}[];
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/goodsOnlineStatusUpd", data);
};

/**
 * 根据商品id 获取该商品的规格列表
 * @param data
 */
export const getGoodsProducts: (data: {
  id: number;
}) => Promise<ApiResult<IStoreProductRow[]>> = (data) => {
  return request("mall/admin/product/getGoodsProducts", data);
};

/**
 * 删除该商品的规格
 * @param data
 */
export const deleteProduct: (data: {
  id: string;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/delProduct", data);
};

/**
 * 编辑规格 上下线规格
 * @param data
 */
export const switchProductStatus: (data: {
  id: number;
  name: any;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/onlineProduct", data);
};

/**
 * 保存或修改规格信息
 * @param data
 */
export const saveProduct: (
  data: IStoreProductRow
) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/product/saveOrUpdateProduct", data);
};

/**
 * 获取上线商品分类列表
 */
export const getGoodsOnlineCategory: (data: {
  id: number;
}) => Promise<ApiResult<IGoodsCateItem[]>> = (data) => {
  return request("mall/admin/category/getOnlineList", data);
};

/**
 * 获取商品分类列表
 */
export const getGoodsCategory: (data: {
  id: number;
}) => Promise<ApiResult<IGoodsCateItem[]>> = (data) => {
  return request("mall/admin/category/getList", data);
};

/**
 * 上下线商品分类，切换status
 */
export const updateCategoryStatus: (data: {
  id: number;
  name: string;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/category/onOff", data);
};

/**
 * 删除商品分类
 * @param data
 */
export const deleteGoodCategory: (data: {
  id: number;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/category/deleteCategory", data);
};

/**
 * 新增或编辑分类
 * @param data
 */
export const saveOrUpdateCategory: (
  data: ISaveUpdateCategoryData
) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/category/saveOrUpdateCategory", data);
};

/**
 * 获取分类详情
 * @param data
 */
export const getCategoryDetail: (data: {
  id: number;
}) => Promise<ApiResult<ISaveUpdateCategoryData>> = (data) => {
  return request("mall/admin/category/detail", data);
};

/**
 * 获取供应商
 */
export const getSupplier: (data: IStoreGoodsPageDataOption) => Promise<ApiResult<ISupplierItem[]>> = (data) => {
  return request("mall/admin/product/getStore2", data);
};
/**
 * 获取订单列表
 */
export const getOrderList: (
  data: IOrderPageData
) => Promise<ApiResult<IOrderPageRow[]>> = (data) => {
  return request("mall/admin/order/pageOrder", data);
};

/**
 * 设置页面为首页 - 页面管理 设为首页
 * @param data
 */
export const setPageHome: (data: { id: number }) => Promise<ApiResult<any>> = (
  data
) => {
  return request("mall/admin/page/setHomePage", data);
};

/**
 * 页面管理删除页面
 * @param data
 */
export const deletePage: (data: {
  ids: any;
  names: any;
}) => Promise<ApiResult<any>> = (data) => {
  return request("merchant/page/delete", data);
};

/**
 * 获取商城订单超时配置
 */
export const getOrderConfigure: (data: {
  id: number;
}) => Promise<ApiResult<IOrderConfig>> = (data) => {
  return request("mall/admin/application/orderConfigure", data);
};

/**
 * 保存商城订单配置
 * @param data
 */
export const saveConfigure: (
  data: IOrderConfigData
) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/application/addConfigure", data);
};

/**
 * 获取省市区列表
 * @param data
 */
export const getAreaList: () => Promise<ApiResult<IDeliverItem[]>> = () => {
  return request("extensions/area/getAreaList", {});
};

/**
 * 获取现有配送地区配置
 * @param data
 */
export const getDelivers: (data: {
  id: number;
}) => Promise<ApiResult<IDeliverConfig>> = (data) => {
  return request("mall/admin/deliver/getDelivers", data);
};

/**
 * 保存配送地区配置
 * @param data
 */
export const saveDeliver: (data: {
  mallId: number;
  areaStr: string;
}) => Promise<ApiResult<any>> = (data) => {
  return request("mall/admin/deliver/addDeliver", data);
};

// 统计商家订单
export const getOrderStatics = (data: any) => {
  return request("/extensions/merchant/order/orderStatics", data);
};

// 商家订单详情
export const getOrderDetail: (data: IOrderDetailData) => Promise<ApiResult<IOrderDetail>> = (data) => {
  return request("/extensions/merchant/order/orderDetail", data);
};

// 订单发货
export const orderShip = (data: any) => {
  return request("/extensions/merchant/order/ship", data);
};
//单个订单冻结
export const orderFreeze = (data: any) => {
  return request("/extensions/merchant/order/freezeOrder", data);
}
//单个订单解冻
export const orderUnfreeze = (data: any) => {
  return request("/extensions/merchant/order/unFreezeOrder", data);
}
//批量订单冻结
export const orderFreezeBatch = (data: any) => {
  return request("/extensions/merchant/order/freezeOrderBatch", data);
}
//批量订单解冻
export const orderUnfreezeBatch = (data: any) => {
  return request("/extensions/merchant/order/unFreezeOrderBatch", data);
}
//单个订单审核
export const orderAudit = (data: any) => {
  return request("/extensions/merchant/order/verifyOrder", data);
}
//批量订单审核
export const orderAuditBatch = (data: any) => {
  return request("/extensions/merchant/order/verifyOrderBatch", data);
}

// 获取区划列表
export const getAreas = (data: any) => {
  return request("/extensions/area/getAreas", data);
};

// 完善收货人信息
export const updateReceiveInfo = (data: any) => {
  return request("/extensions/merchant/order/updateReceiveInfo", data);
};

// 对订单进行备注
export const setRemarkOrder = (data: any) => {
  return request("/extensions/merchant/order/remarkOrder", data);
};

// 异常订单统计
export const getAbnormalStatistics: (data: IAfterSaleOrderPageData) => Promise<ApiResult<IOrderStatisticsItem[]>> = (data) => {
  return request("/extensions/merchant/order/exception/statistics", data);
};

// 异常订单详情
export const getAbnormalDetail: (data: IAbnormalDetailData) => Promise<ApiResult<IAbnormalOrderDetail>> = (data) => {
  return request("/extensions/merchant/order/exception/getDetail", data);
};

//异常订单批量提货
export const batchRetryPickUp = (data: any) => {
  return request("/extensions/merchant/order/batchRetryPickUp", data);
}
//异常订单批量提货结果查询
export const getBatchRetryPickUpResult = (data: any) => {
  return request("/extensions/merchant/order/batchRetryPickUpResult", data);
}
//异常订单退款
export const refundOrder = (data: any) => {
  return request("/extensions/merchant/order/refundOrder", data);
}

// 保存/修改 规则 折扣和限购
export const setSaveOrUpdateRule = (data: any) => {
  return request("/mall/admin/rule/saveOrUpdateRule", data);
};

// 删除规则 折扣和限购
export const delRemoveRule = (data: any) => {
  return request("/mall/admin/rule/removeRule", data);
};

// 规则详情 折扣和限购
export const getRuleDetail = (data: any) => {
  return request("/mall/admin/rule/getOne", data);
};

// 规则列表-限购
export const getPageRules = (data: any) => {
  return request("/mall/admin/rule/pageRules", data);
};

// 获取预览地址
export const getPreviewUrl = (data: any) => {
  return request("/merchant/page/merchant/page/preview", data);
};

/**
 * 根据id获取商城基本信息
 * @param id
 * @returns
 */
export function getMallInfoById(id: any): Promise<ApiResult<any>> {
  return request(`/mall/admin/application/mall/get`, { id });
}

/**
 * 获取商城页面列表
 * @param data
 */
export function getMallPageList(data: IMallPageData): Promise<ApiResult<IMallPageItem[]>> {
  return request('/merchant/page/getPager', data)
}

/**
 * 配置会员价
 */
export function saveProductVipPrice(data: ISaveVipPriceData[]): Promise<ApiResult<any>> {
  return request('mall/admin/product/saveOrUpdateMemberPrice', data)
}

/**
 * 显示隐藏商品
 */
export function hideGoods(data: { id: number }): Promise<ApiResult<any>> {
  return request('mall/admin/product/upIsHidden', data)
}
/**
 * 获取商城配置系统通知人
 */
export function getSysNoticeUser(data: { id: number|string }): Promise<ApiResult<any>> {
  return request('/mall/admin/application/queryMerchantInfos ', data)
}

/**
 * 更新优惠券会员价
 */
export function saveCouponVipPrice(data):Promise<ApiResult<null>> {
  return request('/mall/admin/product/saveOrUpdateProductMemberPrice', data)
}

/**
 * 编辑时获取单个优惠券详情
 * @param data 
 */
export function getCouponDefineInfo(data: {id: string}): Promise<ApiResult<IMallCouponDefineInfo>> {
  return request('mall/admin/product/getCouponDefineInfo', data)
} 

/**
 * 获取商城优惠券批次信息
 */
export function getCouponBatches(data: {id: number | string}):Promise<ApiResult<ICouponManageBatchRow>> {
  return request('mall/admin/product/getCouponBatchInfo', data)
}

/**
 * 保存或者编辑规格：调整库存
 */
export function saveOrUpdateProductNew(data):Promise<ApiResult<null>> {
  return request('mall/admin/product/saveOrUpdateProductNew', data)
}

/**
 * 获取当前商城设置的首页
 */
export function getHomePage(data: {id: number}) {
  return request('mall/admin/application/getHomePage', data)
}
